<style scoped lang="scss">

</style>


<template>
  <div  class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <el-form-item label="园区" prop="location">
        <el-select v-model="queryParams.location" placeholder="请选择园区" clearable style="width: 240px" @change="handleQuery">
          <el-option label="全部" value="" ></el-option>
          <el-option v-for="item in dict.type.user_area" :label="item.label" :value="item.value" ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="开始日期" prop="startDate">
        <el-date-picker v-model="queryParams.startDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd" type="date"  placeholder="请选择日期"  >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束日期" prop="endDate">
        <el-date-picker v-model="queryParams.endDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd" type="date"  placeholder="请选择日期"  >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table  :data="rowList">
      <el-table-column label="用户编号" align="center" prop="customerId" width="120" fixed="left"/>
      <el-table-column label="用户昵称" align="center" prop="customerName" width="120" fixed="left"/>
      <el-table-column label="园区" align="center" prop="location" width="120"/>
      <el-table-column label="金额" align="center" prop="amount" width="120">
        <template v-slot="{row}">
          <span style="color: red" v-if="row.type==='用户消费'|| row.type==='手动减少'">{{row.amount | currency}}</span>
          <span v-else>{{row.amount | currency}}</span>
        </template>
      </el-table-column>
      <el-table-column label="类型" align="center" prop="type" width="120"/>
      <el-table-column label="原因" align="center" prop="reason" min-width="400"/>
      <el-table-column label="创建人" prop="createBy" width="120" align="center"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime,'{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="120" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="{row}">
          <el-button type="text"  icon="el-icon-download" size="mini" @click="rowExport(row)">打印小票</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getData"
    />
  </div>
</template>

<script>
import {balanceListAll, list} from "@/api/shop/balanceDetail";

export default {
  name: "detail",
  dicts:['user_area'],
  data(){
    return{
      rowList:[],
      uid:'',
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        location:'',
        startDate:'',
        endDate:'',
        customerId:null,
        appSource: "pc",
      },
      total:0,
    }
  },
  created() {
    this.queryParams.customerId=this.$route.query.uid
    this.getData()
  },
  methods:{
    getData(){
      list(this.queryParams).then(res=>{
        this.rowList=res.rows
        this.total=res.total
      })
    },
    handleQuery() {
      if(this.queryParams.startDate && !this.queryParams.endDate){
        this.$message.error('请选择结束日期')
        return
      }
      if(this.queryParams.endDate && !this.queryParams.startDate){
        this.$message.error('请选择开始日期')
        return
      }
      this.queryParams.pageNum = 1;
      this.getData();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //打印小票
    rowExport(row){
      this.$router.push({
        path:'/jmreport/consumption',
        query:{
          id:'931398146240327680',
          rowId:row.id
        }
      })
    },
  },
}
</script>
